<script type="text/javascript">
	//日期比较
	function compare(oldDate  , newDate) { 
		if(typeof(newDate)!="object" && newDate.constructor != Date){
			return -2; 
		}
		var d = oldDate.getTime() - newDate.getTime();
		if(d>0){
			return 1;
		}else{
			if(d==0){
				return 0;
			}else {
				return -1;
			}
		}
	}
	//针对不同的时间单位做加运算，得到日期年月日等加数字后的日期
	function dateAdd( date , interval , number) {
		switch(interval) {
		case "y" : 
			date.setFullYear(date.getFullYear()+number); 
			return date; 
		case "q" : 
			date.setMonth(date.getMonth()+number*3);
			return date; 
		case "m" : 
			date.setMonth(date.getMonth()+number);
			return date; 
		case "w" : 
			date.setDate(date.getDate()+number*7);
			return date; 
		case "d" : 
			date.setDate(date.getDate()+number);
			return date; 
		case "h" : 
			date.setHours(date.getHours()+number);
			return date; 
		case "m" : 
			date.setMinutes(date.getMinutes()+number); 
			return date; 
		case "s" : 
			date.setSeconds(date.getSeconds()+number);
			return date; 
		default : 
			date.setDate(d.getDate()+number);
			return date; 
		}
	}

	function parseDate(str) {
		var d = new Date(Date.parse(str.replace(/-/g,"/")));   
		return d;
	}
	
	// 计算两个日期的间隔天数
	function DateDiff(sDate1, sDate2){ 
		var aDate, oDate1, oDate2, iDays
		aDate = sDate1.split("-")
		oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]) //转换为12-18-2002格式
		aDate = sDate2.split("-")
		oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])
		iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 /24) //把相差的毫秒数转换为天数
		return iDays
	} 

   //格式化日期格式
   //var dates = format( new Date() , "yyyy-MM-DD hh:mm:ss");
       function format(date , formatStr){ 
		var str = formatStr; 
		str=str.replace(/yyyy|YYYY/,date.getFullYear()); 
		str=str.replace(/yy|YY/,(date.getYear() % 100)>9?(date.getYear() % 100).toString():"0" + (date.getYear() % 100)); 
		str=str.replace(/MM/,date.getMonth()>8?(date.getMonth()+1).toString():"0" + (date.getMonth()+1)); 
		str=str.replace(/M/g,date.getMonth()+1); 
		str=str.replace(/dd|DD/,date.getDate()>9?date.getDate().toString():"0" + date.getDate()); 
		str=str.replace(/d|D/g,date.getDate()); 
		str=str.replace(/hh|HH/,date.getHours()>9?date.getHours().toString():"0" + date.getHours()); 
		str=str.replace(/h|H/g,date.getHours()); 
		str=str.replace(/mm/,date.getMinutes()>9?date.getMinutes().toString():"0" + date.getMinutes()); 
		str=str.replace(/m/g,date.getMinutes()); 
		str=str.replace(/ss|SS/,date.getSeconds()>9?date.getSeconds().toString():"0" + date.getSeconds()); 
		str=str.replace(/s|S/g,date.getSeconds()); 
		return str; 
	}

	/*应用*/
	var cssrain={};
	var datestr1 =  '2008-04-21' ;
	var datestr2 =  '2008-05-24' ;
	cssrain.date1 = parseDate(datestr1);
	cssrain.date2 = parseDate(datestr2);
	var days = DateDiff( datestr1 ,datestr2);
	var newArr=new Array();
	for(var i=0;i<(days-1);i++){
		cssrain.date1 = dateAdd( cssrain.date1 , "d" , 1);
		newArr.push(  format(cssrain.date1,"yyyy-MM-DD")   );
	} 
	alert("中间时间为："+(newArr.constructor==Array) +" ："+newArr);
	/*
	for(var i=0;i<newArr.length;i++){
		alert(newArr[i]);
	}
	*/
</script>
